package com.houseman.workFlow.service.impl;

import java.util.List;

import com.houseman.workFlow.bean.TaskArea;
import com.houseman.workFlow.bean.WorkFlowBean;
import com.houseman.workFlow.dao.GraphDao;
import com.houseman.workFlow.dao.RoleDao;
import com.houseman.workFlow.dao.TaskAreaDao;
import com.houseman.workFlow.dao.WorkFlowDao;
import com.houseman.workFlow.dao.impl.GraphDaoImpl;
import com.houseman.workFlow.dao.impl.RoleDaoImpl;
import com.houseman.workFlow.dao.impl.TaskAreaDaoImpl;
import com.houseman.workFlow.dao.impl.WorkFlowDaoImpl;
import com.houseman.workFlow.dto.Approver;
import com.houseman.workFlow.dto.NextStepInfo;
import com.houseman.workFlow.service.WorkFlowService;

public class WorkFlowServiceImpl implements WorkFlowService{

	//dao
	WorkFlowDao dao = new WorkFlowDaoImpl();
	TaskAreaDao tdao = new TaskAreaDaoImpl();
	GraphDao gdao = new GraphDaoImpl();
	RoleDao rdao = new RoleDaoImpl();

	/**
	 * 获取流程信息
	 * @param workId
	 * @return
	 * @throws Exception
	 */
	public WorkFlowBean queryWorkFlowInfo(int workId) throws Exception {
		return dao.getWorkFlowInfo(workId);
	}
	
	/**
	 * 启动流程，保存流程信息
	 * @param info
	 * @throws Exception
	 */
	public String startWorkFlow(WorkFlowBean info) throws Exception {
		int i = dao.startWorkFlow(info);
		return String.valueOf(i);
	}
	
	/**
	 * 关闭流程
	 * @param wfid
	 * @throws Exception
	 */
	public void closeWorkFlow(int workId) throws Exception {
		dao.closeWorkFlow(workId);
	}
	
	/**
	 * 获得下一办理相关信息
	 * @param wfid
	 * @throws Exception
	 */
	public List<NextStepInfo> queryNextStepInfo(int wfId, int step) throws Exception {
		return tdao.queryNextStepInfo(wfId, step);
	}

	/**
	 * 查询当前办理的任务信息
	 * @param wfId
	 * @param step
	 * @return
	 * @throws Exception
	 */
	public TaskArea queryTaskAreaByStep(int wfId, int step) throws Exception {
		return tdao.queryTaskAreaByStep(wfId, step);
	}

	/**
	 * 修改流程一下已办理信息
	 * @param workId
	 * @param step
	 * @param approve
	 * @throws Exception
	 */
	public void updateNextStepInfo(WorkFlowBean info) throws Exception {
		dao.updateNextStepInfo(info);
	}

	/**
	 * 根据graphId查询graph信息
	 * @param graphId
	 * @return
	 * @throws Exception
	 */
	public WorkFlowBean queryNewBuildGraph(int graphId) throws Exception {
		return gdao.queryNewBuildGraph(graphId);
	}

	/**
	 * 查询审批人
	 * @param graphId
	 * @return
	 * @throws Exception
	 */
	public List<Approver> queryApprovals(String roleId) throws Exception {
		return rdao.queryApproverById(roleId);
	}

}
